package com.lkc.service.impl;

import com.lkc.annotation.LogMethod;
import com.lkc.bean.Orders;
import com.lkc.mapper.OrdersDao;
import com.lkc.service.OrdersService;
import com.lkc.util.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDate;
import java.util.List;

@Service
public class OrdersServiceImpl implements OrdersService {

    @Autowired
    private OrdersDao ordersDao;

    @Override
    @LogMethod(serviceName = "订单服务", recordParam = true, recordReturn = true)
    public Orders add(Orders orders) {
        ordersDao.add(orders);
        return ordersDao.one(orders.getOrderId());
    }

    @Override
    @LogMethod(serviceName = "订单服务", recordParam = true, recordReturn = true)
    public int del(Integer orderId) {
        return ordersDao.del(orderId);
    }

    @Override
    @LogMethod(serviceName = "订单服务", recordParam = true, recordReturn = true)
    public Orders edit(Orders orders) {
        ordersDao.edit(orders);
        return ordersDao.one(orders.getOrderId());
    }

    @Override
    @LogMethod(serviceName = "订单服务", recordParam = true, recordReturn = true)
    public Orders one(Integer orderId) {
        return ordersDao.one(orderId);
    }

    @Override
    @LogMethod(serviceName = "订单服务", recordParam = true, recordReturn = false)
    public void page(Page page, Orders orders) {
        int count = ordersDao.pageCount(orders);
        List<Orders> data = ordersDao.page(page, orders);
        page.setCount(count);
        page.setData(data);
    }

    @Override
    @LogMethod(serviceName = "订单服务", recordParam = true, recordReturn = false)
    public List<Orders> all(Orders orders) {
        return ordersDao.all(orders);
    }

    @Override
    @LogMethod(serviceName = "订单服务", recordParam = true, recordReturn = false)
    public List<Orders> findByBuyerId(Integer buyerId) {
        return ordersDao.findByBuyerId(buyerId);
    }

    @Override
    @LogMethod(serviceName = "订单服务", recordParam = true, recordReturn = true)
    public int getCountByDate(LocalDate date) {
        return ordersDao.getCountByDate(date);
    }
}
